﻿Imports System.Data
Imports System.Data.SqlClient
Public Class HocKyDAO
    Public Sub LoadCombobox(ByVal cbx As ComboBox, ByVal sql As String)
        Dim load As DataProvider = New DataProvider
        cbx.DataSource = load.Sql_ExecuteTable(sql)
    End Sub
    Public Sub LoadGridView(ByVal dgv As DataGridView, ByVal sql As String)
        Dim load As DataProvider = New DataProvider
        dgv.DataSource = load.Sql_ExecuteTable(sql)
    End Sub
    Public Function ThemHocKy(ByVal hkInsert As HocKyDTO) As Boolean
        Dim Insert As DataProvider = New DataProvider
        Dim sql As String = String.Format("Insert_HocKy")
        Dim pr As SqlParameter() = {New SqlParameter("@MaHocKi", hkInsert.MaHocKy),
                                    New SqlParameter("@TenHocKi", hkInsert.TenHocKy),
                                    New SqlParameter("@NamHoc", hkInsert.NamHoc)}
        Dim cmd As SqlCommand = New SqlCommand(sql)
        cmd.CommandType = CommandType.StoredProcedure
        For i As Integer = 0 To pr.Count() - 1
            cmd.Parameters.Add(pr(i))
        Next
        Return Insert.SQL_ExecuteNonQuery(cmd)
    End Function
    Public Function XoaHocKy(ByVal id As String) As Boolean
        Dim Remove As DataProvider = New DataProvider
        Dim sql As String = String.Format("Delete_HocKy")
        Dim pr As SqlParameter = New SqlParameter("@MaHocKy", id)
        Dim cmd As SqlCommand = New SqlCommand(sql)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.Add(pr)
        Return Remove.SQL_ExecuteNonQuery(cmd)
    End Function
    Public Function SuaHocKy(ByVal hkUpdate As HocKyDTO) As Boolean
        Dim Update As DataProvider = New DataProvider
        Dim sql As String = String.Format("Update_HocKy")
        Dim pr As SqlParameter() = {New SqlParameter("@MaHocKy", hkUpdate.MaHocKy),
                                    New SqlParameter("@TenHocKy", hkUpdate.TenHocKy),
                                    New SqlParameter("@NamHoc", hkUpdate.NamHoc)}
        Dim cmd As SqlCommand = New SqlCommand(sql)
        cmd.CommandType = CommandType.StoredProcedure
        For i As Integer = 0 To pr.Count() - 1
            cmd.Parameters.Add(pr(i))
        Next
        Return Update.SQL_ExecuteNonQuery(cmd)
    End Function
End Class
